package ferus.tigris.lines.views;

import ferus.tigris.lines.GameView;
import ferus.tigris.lines.R;
import ferus.tigris.lines.Builders.ImagesPool;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;

public class ForegroundView implements AbstractView {
	Bitmap image;
	Rect srcRect;
	Rect dstRect;
	private SimpleLinearSprite sun;
	Paint paint = new Paint();

	public ForegroundView(GameView gameView) {
		image = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.hills);
		int w = gameView.getWidth() > image.getWidth() ? gameView.getWidth() : image.getWidth();
		
		int offset = gameFieldHeight(gameView) - gameView.getHeight() + foregroundImageHeight();
		if(offset < 0)offset = 0;
		
		srcRect = new Rect(0, 0, image.getWidth(), image.getHeight());
		dstRect = new Rect(gameView.getWidth() - w, gameView.getHeight() - image.getHeight() + offset, gameView.getWidth(), gameView.getHeight() + offset);
		
		sun = new SimpleLinearSprite(ImagesPool.instance(gameView).sun(), 13, 100);
		sun.setPosition(new Point(gameView.getWidth(), 0));
		paint.setAntiAlias(true);
		paint.setFilterBitmap(true);
		paint.setDither(true);
	}

	protected int foregroundImageHeight() {
		return image.getHeight()/8;
	}

	protected int gameFieldHeight(GameView gameView) {
		return gameView.getHeight()/2 + gameView.getWidth()*2/3;
	}

	public void draw(Canvas canvas) {
		canvas.drawBitmap(image, srcRect, dstRect, paint);
		sun.draw(canvas);
	}

	public void setPosition(Point position) {}

	public void setRealSpriteWidth(int px) {}
}